package com.luych.toolbox.common.page;

import com.luych.toolbox.common.constant.PageConstant;

import java.util.ArrayList;
import java.util.List;

public class CommonPageParam implements PageParam {

    private long pageNumber = PageConstant.DEFAULT_PAGE_NUMBER;
    private long pageSize = PageConstant.DEFAULT_PAGE_SIZE;
    private List<Sort> sorts = new ArrayList<>();

    public CommonPageParam() {
    }

    public CommonPageParam(long pageNumber, long pageSize, List<Sort> sorts) {
        this.pageNumber = pageNumber;
        this.pageSize = pageSize;
        this.sorts = sorts;
    }

    public static CommonPageParam getInstance(PageParam pageParam) {
        return new CommonPageParam(pageParam.getPageNumber(), pageParam.getPageSize(), pageParam.getSorts());
    }

    public static CommonPageParam getInstance() {
        return new CommonPageParam();
    }

    @Override
    public long getPageNumber() {
        return pageNumber;
    }

    public CommonPageParam setPageNumber(long pageNumber) {
        this.pageNumber = pageNumber;
        return this;
    }

    @Override
    public long getPageSize() {
        return pageSize;
    }

    public CommonPageParam setPageSize(long pageSize) {
        this.pageSize = pageSize;
        return this;
    }

    @Override
    public List<Sort> getSorts() {
        return sorts;
    }

    public CommonPageParam setSorts(List<Sort> sorts) {
        this.sorts = sorts;
        return this;
    }

    public CommonPageParam addSort(Sort sort) {
        this.sorts.add(sort);
        return this;
    }
}
